/*
 * smsleep.c
 * Various clock functions for use with the BRAIN board
 * Andrew Kovacs Sept. 27, 2008
 */

void sleep(int deciseconds);
void macroSleep(int deciseconds, short chan, short threshold);

void sleep(int deciseconds)
{
	unsigned int startTime = getClock(0);
	//while the time is less than the time we want to stop sleeping, read a value from a switch
	//the value reading prevents the brain from shutting off from inactivity
	while(getClock(startTime) < (int)(((deciseconds * 5)) * 0.9)){getSwitch(0);}
}

//Sleep function tht has checking for a cancel of a macro
//use this with macros that you need to support canceling in
void macroSleep(int deciseconds, short chan, short threshold)
{
 unsigned int startTime = getClock(0);
 //while the time is less than the time we want to stop sleeping, read a value from a switch
 //the value reading prevents the brain from shutting off from inactivity
 while(getClock(startTime) < (deciseconds * 5))
 {
   getSwitch(0);
   if(getRcValue(chan, 8, 110) < threshold)
     break;
 }
}

